package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Home-pc
 * Date: 2023-08-17
 * Time: 10:49
 */
public class AddOperation implements IOperation{

    @Override
    public void work(BookList bookList) {
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入书的名字");
        String name=sc.nextLine();
        System.out.println("请输入书的作者");
        String author=sc.nextLine();
        System.out.println("请输入书的类型");
        String describe=sc.nextLine();
        System.out.println("请输入书的价格");
        double price=sc.nextDouble();

        Book book =new Book(name,author,describe,price);//new一个新的book对象，并完成初始化
        int pos=bookList.getUsedSized();//获取booklist中的书总数，为增加新书获取位置
        bookList.setBooks(pos,book);//将新书放置在数组库中的最后一个位置
        bookList.setUsedSized(pos+1);//书的总数+1
        System.out.println("添加书籍成功");
    }
}
